<template>
  <div class="menu-container">
    <RouterLink
      :exact="n.exact"
      v-for="n in items"
      :key="n.link"
      :to="{ name: n.name }"
      active-class="active"
      exact-active-class=""
    >
      <div class="icon"><Icon :type="n.icon" /></div>
      <p>{{ n.title }}</p>
    </RouterLink>
  </div>
</template>

<script>
import Icon from "../../Icon/index.vue";
export default {
  components: {
    Icon,
  },
  data() {
    return {
      items: [
        {
          name: "Home",
          icon: "home",
          title: "首页",
          exact: true,
        },
        {
          name: "Blog",
          icon: "blog",
          title: "文章",
          exact: false, //激活状态是否要精确匹配
        },
        {
          name: "About",
          icon: "info",
          title: "关于我",
          exact: true,
        },
        {
          name: "Project",
          icon: "code",
          title: "项目&效果",
          exact: true,
        },
        {
          name: "Message",
          icon: "chat",
          title: "留言板",
          exact: true,
        },
      ],
    };
  },
  methods: {
    isActive(item) {
      var link = item.link.toLowerCase(); // 菜单的链接地址
      var curPathname = location.pathname.toLowerCase(); // 当前浏览器的访问路径
      if (item.startWith) {
        return curPathname.startsWith(link);
      } else {
        return curPathname === link;
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import "~@/styles/mixin.less";
@import "~@/styles/var.less";
.menu-container {
  width: 100%;
  a {
    margin: 10px 0;
    height: 35px;
    line-height: 35px;
    display: flex;
    align-items: center;
    padding: 5px 50px 5px;
    color: @gray;
    &:hover {
      color: #fff;
    }
    &.active {
      background-color: #2d2d2d;
    }
    .icon {
      font-size: 24px;
    }
    p {
      margin-left: 5px;
      font-size: 16px;
    }
  }
}
</style>